package com.szrt.cookie;

import java.io.IOException;
import java.util.Date;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class SesssionServlet extends HttpServlet {

	private static final long serialVersionUID = -3805640999174935654L;
	
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		HttpSession  session = request.getSession();
		String time = new Date().toString();
		if(null == session.getAttribute("lastTime")){
			session.setAttribute("lastTime", time);
		}else{
			session.setAttribute("lastTime", session.getAttribute("currentTime"));
		}
		session.setAttribute("currentTime", time);
		
		//重定向
		response.sendRedirect(request.getContextPath()+"/sessionSuccess.jsp");
		
	}

}
